using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HoleTrigger : TriggerBase
{
    [SerializeField] private Transform _responseTrans;
    [SerializeField] private float _responseInterval = .3f;
    private GameObject _playerBullet;
    protected override void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("PlayerBullet") == false)
            return;

        Object_PlayerBullet objectBullet = other.GetComponent<Object_PlayerBullet>();

        if (objectBullet == null || objectBullet.GetCurrentBulletSpeed().x < 0)
            return;

        _playerBullet = other.gameObject;

        _playerBullet.SetActive(false);

        StartCoroutine(WaitResponseCo(_playerBullet));
    }

    private IEnumerator WaitResponseCo(GameObject bullet)
    {
        yield return new WaitForSeconds(_responseInterval);

        CreateRepsonseBullet(bullet);
    }

    private void CreateRepsonseBullet(GameObject bullet)
    {
        bullet.SetActive(true);
        
        bullet.transform.position = _responseTrans.position;

        bullet.GetComponent<Object_PlayerBullet>().SetupBullet(Vector2.down, 0, 15);
    }
}
